package cn.com.colasoft.guava;

import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lizhitao on 2017/9/10.
 * Guava函数式编程测试
 */
public class FunctionTest {
    public static void main(String[] args) {
        ArrayList<Integer> list = Lists.newArrayList(1, 2, 3, 4, 5, 6);
        List<Integer> transform = Lists.transform(list, new Function<Integer, Integer>() {

            @Override
            public Integer apply(Integer integer) {
                return integer * 2;
            }
        });


        System.out.println(transform);

        Iterable<Integer> filter = Iterables.filter(list, new Predicate<Integer>() {
            @Override
            public boolean apply(Integer input) {
                return input > 4;
            }
        });

        System.out.println(filter);

    }



}
